<?xml version="1.0" encoding="UTF-8"?>
<package targetNamespace="OGoSyncAccounts" xmlns="http://www.bpmi.org/2002/BPML/process">
	<process id="dab39f56" persistent="false" name="OGoSyncAccounts">
		<event activity="OGoSyncAccounts" exclusive="false"/>
		<context atomic="true">
			<faults/>
		</context>
		<action name="OGoSyncAccounts" id="90377c6a" extensionAttributes="OGoSyncAccounts/90377c6a">
			<input property="InputMessage" formatter="StandardRaw"/>
			<output>
				<source property="InputMessage"/>
			</output>
			<action name="actionActivity" id="f872854a" extensionAttributes="OGoSyncAccounts/f872854a">
				<input property="SELECT_accounts" formatter="StandardXML"/>
				<attributes xmlns="">
					<extension name="activityName">sqlSelect</extension>
					<extension name="jdbcSource">OpenGroupware</extension>
					<extension name="query">SELECT number, login, firstname, &#xd;
       name AS lastname, &#xd;
       company_id AS account_id&#xd;
FROM person&#xd;
WHERE is_account = 1</extension>
					<extension name="isSavedInContext">true</extension>
					<extension name="description">Get all accounts from OpenGroupware database</extension>
				</attributes>
			</action>
			<foreach name="foreachActivity" id="b600fe7" select="/ResultSet/row" formatter="StandardXML">
				<source property="SELECT_accounts" xpath=""/>
				<action name="actionActivity" id="a1bf9d45" extensionAttributes="OGoSyncAccounts/a1bf9d45">
					<input property="value_account_id" formatter="StandardRaw"/>
					<output>
						<source property="current"/>
					</output>
					<attributes xmlns="">
						<extension name="activityName">assign</extension>
						<extension name="assign_xpath">/row/account_id/text()</extension>
						<extension name="assign_root_name">root</extension>
						<extension name="isSavedInContext">true</extension>
						<extension name="description">Get login from row</extension>
					</attributes>
				</action>
				<action name="actionActivity" id="d9315190" extensionAttributes="OGoSyncAccounts/d9315190">
					<input property="value_number" formatter="StandardRaw"/>
					<output>
						<source property="current"/>
					</output>
					<attributes xmlns="">
						<extension name="activityName">assign</extension>
						<extension name="assign_xpath">/row/number/text()</extension>
						<extension name="assign_root_name">root</extension>
						<extension name="isSavedInContext">true</extension>
						<extension name="description">Get Number from select result</extension>
					</attributes>
				</action>
				<action name="actionActivity" id="be7d50f5" extensionAttributes="OGoSyncAccounts/be7d50f5">
					<input property="value_login" formatter="StandardRaw"/>
					<output>
						<source property="current"/>
					</output>
					<attributes xmlns="">
						<extension name="activityName">assign</extension>
						<extension name="assign_xpath">/row/login/text()</extension>
						<extension name="assign_root_name">root</extension>
						<extension name="isSavedInContext">true</extension>
						<extension name="description">Get login from select results</extension>
					</attributes>
				</action>
				<action name="actionActivity" id="7ce7c1c8" extensionAttributes="OGoSyncAccounts/7ce7c1c8">
					<input property="value_firstname" formatter="StandardRaw"/>
					<output>
						<source property="current"/>
					</output>
					<attributes xmlns="">
						<extension name="activityName">assign</extension>
						<extension name="assign_xpath">/row/firstname/text()</extension>
						<extension name="assign_root_name">root</extension>
						<extension name="isSavedInContext">true</extension>
						<extension name="description">Get firstname from select results</extension>
					</attributes>
				</action>
				<action name="actionActivity" id="5d80c20a" extensionAttributes="OGoSyncAccounts/5d80c20a">
					<input property="value_lastname" formatter="StandardRaw"/>
					<output>
						<source property="current"/>
					</output>
					<attributes xmlns="">
						<extension name="activityName">assign</extension>
						<extension name="assign_xpath">/row/lastname/text()</extension>
						<extension name="assign_root_name">root</extension>
						<extension name="isSavedInContext">true</extension>
						<extension name="description">Get last name from select results</extension>
					</attributes>
				</action>
				<action name="actionActivity" id="f88b6e93" extensionAttributes="OGoSyncAccounts/f88b6e93">
					<input property="value_count" formatter="StandardXML"/>
					<attributes xmlns="">
						<extension name="activityName">sqlSelect</extension>
						<extension name="jdbcSource">MOA</extension>
						<extension name="query">SELECT COUNT(*) FROM ogo_account&#xd;
WHERE account_id = $value_account_id;</extension>
						<extension name="isSavedInContext">true</extension>
						<extension name="description">Get row count from database for account id in ogo_account</extension>
					</attributes>
				</action>
				<action name="actionActivity" id="3f54ad87" extensionAttributes="OGoSyncAccounts/3f54ad87">
					<input property="value_count" formatter="StandardRaw"/>
					<output>
						<source property="value_count"/>
					</output>
					<attributes xmlns="">
						<extension name="activityName">assign</extension>
						<extension name="assign_xpath">/ResultSet/row/_count____/text()</extension>
						<extension name="assign_root_name">root</extension>
						<extension name="isSavedInContext">true</extension>
						<extension name="description"/>
					</attributes>
				</action>
				<switch name="switchActivity" id="f7febdcd">
					<case id="b2e09c65">
						<condition expression="$value_count;==0"/>
						<context atomic="false">
							<faults/>
						</context>
						<action name="actionActivity" id="263557e8" extensionAttributes="OGoSyncAccounts/263557e8">
							<attributes xmlns="">
								<extension name="activityName">sqlExecute</extension>
								<extension name="jdbcSource">MOA</extension>
								<extension name="issqlblock">false</extension>
								<extension name="query">INSERT INTO ogo_account&#xd;
(account_id, number, login, firstname, lastname) &#xd;
VALUES ($value_account_id;, '$value_number;', '$value_login;', '$value_firstname;', '$value_lastname;')</extension>
								<extension name="description">Insert account information into account table (ogo_account).</extension>
							</attributes>
						</action>
					</case>
					<default id="f8105a94">
						<condition/>
						<context atomic="false">
							<faults/>
						</context>
						<action name="actionActivity" id="482006b3" extensionAttributes="OGoSyncAccounts/482006b3">
							<attributes xmlns="">
								<extension name="activityName">sqlExecute</extension>
								<extension name="jdbcSource">MOA</extension>
								<extension name="issqlblock">false</extension>
								<extension name="query">UPDATE ogo_account&#xd;
SET number = '$value_number;',&#xd;
    login = '$value_login;',&#xd;
    firstname = '$value_firstname;',&#xd;
    lastname ='$value_lastname;'&#xd;
WHERE account_id = $value_account_id;</extension>
								<extension name="description">Update account information in account table (ogo_account)</extension>
							</attributes>
						</action>
					</default>
				</switch>
				<context atomic="false">
					<exception id="c8ce647d">
						<action name="actionActivity" id="bfdf539f" extensionAttributes="OGoSyncAccounts/bfdf539f">
							<output>
								<source property="error"/>
							</output>
							<attributes xmlns="">
								<extension name="activityName">sendMail</extension>
								<extension name="isInlineText">true</extension>
								<extension name="cc"/>
								<extension name="bcc"/>
								<extension name="attachmentName"/>
								<extension name="subject">BIE Exception in OGoAccountSync </extension>
								<extension name="from">bie@morrison-ind.com</extension>
								<extension name="to">cisstaff@morrison-ind.com</extension>
								<extension name="description"/>
							</attributes>
						</action>
						<context atomic="false">
							<faults/>
						</context>
					</exception>
					<faults/>
				</context>
			</foreach>
			<attributes xmlns="">
				<extension name="activityName">eventAction</extension>
				<extension name="isSavedInContext">true</extension>
				<extension name="description"/>
			</attributes>
		</action>
	</process>
</package>
